using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Windows.Forms;

namespace IWS.Lib.SingleSignOn
{
	public enum WebServiceSecurityMode
	{
		Static,
		Dynamic
	}
	public class SecurityContext
	{
		private static WebServiceSecurityMode S_MODE = WebServiceSecurityMode.Static;

		public static WebServiceSecurityMode Mode
		{
			get { return S_MODE; }
			set { S_MODE = value; }
		}

		private static string sKey = null;

		/// <summary>
		/// Gets or sets the current service key for the single sign on web services.
		/// </summary>
		public static string CurrentKey
		{
			get 
			{
				if (string.IsNullOrEmpty(sKey))
					throw new ApplicationException("Service key not initialized.");

				return sKey; 
			}
			set { sKey = value; }
		}

		public static bool InitializeKey(string username, string password)
		{
			WebServiceMembershipProvider prov = System.Web.Security.Membership.Provider as WebServiceMembershipProvider;
			if (prov != null)
				return prov.GenerateSession(username, password);
			else
				throw new ApplicationException("Can't instantiate the membership provider");
		}
	}
}
